// pages/manager/reserve/reserve.js
const bb=wx.cloud.database()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    color1: "#FF8D1A",
    color2: "white",
    orderInfo1:[
  
    ],
    orderInfo2:[
      
    ],
    orderInfo:[],
    
    studentId:null,
  },
  goAllorder:function() {
    var that = this
    that.setData({
      orderInfo: that.data.orderInfo2,
      color2: "#FF8D1A",
      color1: "white",
    })
  },
  goOrder:function() {
    var that = this
    that.setData({
      orderInfo: that.data.orderInfo1,
      color1: "#FF8D1A",
      color2: "white",
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */


  onLoad: function (options) {
    
    util.time()
    // var that=this
    // wx.getStorage({
    //   key: "student",
    //   success (res) {
    //     that.setData({
    //       studentId:res.data.student_id
    //     })
    //     console.log(res.data.student_id)
    //   }
    // })
    
   
    // //  var studentid=that.data.studentId
    // console.log(studentid)
    // bb.collection("order_info").where({
    //   "student.id": studentid,
    //   "order_status":"0",
      
    // }).orderBy("order_time","desc").get({
    //   success:res=>{
    //   this.setData({
    //     orderInfo1: res.data,
    //     orderInfo: res.data
    //   })
    //   console.log(orderInfo1)
    //   }    
    // })
    // bb.collection("order_info").where({
    //   "student.id": studentid,
    // }).orderBy("order_time","desc").get({
    //   success:res=>{
    //   this.setData({
    //     orderInfo2: res.data
    //   })
    //   console.log(orderInfo1)
    //   }    
    // })
  },

  onClickLeft() {
    wx.navigateBack()
  },
  /**
  * 生命周期函数--监听页面显示
  */
 onShow: function () {
  
 
  var that =this
  wx.getStorage({
    key: "student",
    success (res) {
      that.setData({
        studentId:res.data.student_id
      })
     
      console.log("11-------"+res.data.student_id)
    }
  })
  
  console.log("22-----"+that.data.studentId)
  var studentid=this.data.studentId
  bb.collection("order_info").where({
    "student.id": studentid,
    "order_status":"0",
    
  }).orderBy("order_time","desc").get({
    success:res=>{
    this.setData({
      orderInfo1: res.data,
      orderInfo: res.data
    })
    // console.log(orderInfo1)
    }   
  })
  bb.collection("order_info").where({
    "student.id": studentid,
  }).orderBy("order_time","desc").get({
    success:res=>{
    this.setData({
      orderInfo2: res.data
    })
    // console.log(orderInfo1)
    }
  })
   
   util.time()
 }
})